local U = require "packages/utility/utility"
local ls = require "packages/lvshi/utility"

local skill = fk.CreateSkill {
  name = "scroll_skill",
}

skill:addEffect("cardskill", {
  prompt = "#scroll_skill",
  mod_target_filter = Util.TrueFunc,
  max_phase_use_time = 1,
  can_use = function(self, player, card, extra_data)
    if self:withinTimesLimit(player, Player.HistoryPhase, card, "scroll", player) then
      return Util.CanUseToSelf
    end
  end,
  on_effect = function(self, room, effect)
    if effect.to.dead then return end
    local n = 3
    effect.extra_data = effect.extra_data or {}
    n = n + (effect.extra_data.additionalScroll or 0)
    local cards = ls.discover(effect.to, "basic", n)
    --local choosed_cards, _ = U.askforChooseCardsAndChoice(effect.to, cards, {"OK"}, skill.name, "#discovery", {}, 1, 1, cards)
    local choosed_cards, _ = room:askToChooseCardsAndChoice(effect.to, {
      cards = cards,
      choices = {"OK"},
      skill_name = skill.name,
      prompt = "#discovery",
      min_num = 1,
      max_num = 1,
      all_cards = cards
    })
    if #choosed_cards > 0 then
      room:obtainCard(effect.to, choosed_cards, true, fk.ReasonJustMove, effect.to, skill.name)
      effect.extra_data.name = Fk:getCardById(choosed_cards[1]).trueName
    end
  end,
})

Fk:loadTranslationTable{
  -- TODO: move them
  ["#discovery"] = "发现：请选择一张牌获得",
}

return skill